﻿using ZeroBlog.Core.Domains.Blog;
using ZeroSum.Domain.Repositories;

namespace ZeroBlog.Core.DomainServices.Categories;

public class CategorySeedProvider : IDataSeedProvider
{
    private readonly IRepository<Category> _repository;

    public CategorySeedProvider(IRepository<Category> repository)
    {
        _repository = repository;
    }

    public async Task SeedAsync(IServiceProvider serviceProvider)
    {
        if (await _repository.CountAsync() <= 0)
        {
            var categories = new List<Category>
            {
                new() {Name = ".Net",AliasName = "net"},
                new() {Name = "Java",AliasName = "java"},
                new() {Name = "Vue",AliasName = "vue"},
                new() {Name = "书籍",AliasName = "book"},
                new() {Name = "影视",AliasName = "movie"},
                new() {Name = "24小时快讯",AliasName = "flash"},
            };


            await _repository.AddRangeAsync(categories);
            await _repository.SaveChangesAsync();
        }
    }

    public int Order { get; set; } = 2;
}